//
//  CommunityLinkModel.m
//  WeCommunity
//
//  Created by mac on 2017/8/9.
//  Copyright © 2017年 lzy. All rights reserved.
//

#import "CommunityLinkModel.h"

@implementation CommunityLinkModel

-(NSString *)formatTime
{
    _formatTime = [TimeStampTool formatDateWithDynamicTime:self.createTime];
    return _formatTime;
}

-(BOOL)isLike
{
    if (![UserInfoManger shared].isLogin) {
        return NO;
    }
    for (NSString * objectId in self.likeList) {
        if ([objectId isEqualToString:[UserInfoManger shared].contact.objectId]) {
            return YES;
        }
    }
    return NO;
}

-(long)likeTotalNum
{
    return (float)self.likeList.count;
}

-(NSString *)formatLikeTotalNum
{
    if (self.likeTotalNum  < 10000) {
        _formatLikeTotalNum = [NSString stringWithFormat:@"%ld",self.likeTotalNum];
    }else if (self.likeTotalNum  >= 10000){
        _formatLikeTotalNum = [NSString stringWithFormat:@"%.1lfW",self.likeTotalNum / 10000.0];
    }
    return _formatLikeTotalNum;
}

+(CommunityLinkModel *)setValueFormObject:(id)object
{
    CommunityLinkModel * model = [CommunityLinkModel new];
    model.objectId = [object objectForKey:@"objectId"];
    model.dataType = [[object objectForKey:@"dataType"] intValue];
    model.content = [object objectForKey:@"content"];
    model.linkUrl = [object objectForKey:@"linkUrl"];
    model.likeList = [object objectForKey:@"likeList"];
    model.createDate = [object objectForKey:@"createdAt"];
    model.createTime = [NSString stringWithFormat:@"%.0lf",[model.createDate timeIntervalSince1970] * 1000];
    //图片
    AVFile * file = [object objectForKey:@"imageUrl"];
    if (![file isEqual: [NSNull null]] && file.url.length > 0) {
        model.imageUrl = file.url;
    }

    //用户信息
    model.contact = [ContactModel setValueFormObject:[object objectForKey:@"contact"]];
    return model;
}

@end
